from django.shortcuts import render
from .models import ogPic
from .forms import picForm


import os
from datetime import datetime


# Create your views here.
def getPic(request):
    # 判断是否为 post 方法提交
    if request.method == "POST":
        af = picForm(request.POST, request.FILES)
        # 判断表单值是否和法
        if af.is_valid():
            name = af.cleaned_data['name']
            pic = ogPic(name=name)
            pic.save()

            print(name)


            afterTreatmentPic = os.listdir('/Users/qimingyang/Desktop/GraduationProject/peopleCount/media/90')


            return render(request, 'count/index.html', context={"pic":pic,"af":af,"atp":afterTreatmentPic})
    else:
        af = picForm()
        print("else",af)
        return render(request, 'count/index.html', context={"af":af})
